﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR.Client;

namespace learun.util
{
    /// <summary>
    /// 版 本 Learun-ADMS-Core 力软敏捷开发框架
    /// Copyright (c) 2019-present 力软信息技术（苏州）有限公司
    /// 创建人：tobin
    /// 日 期：2019.11.05
    /// 描 述：发送消息给SignalR集结器
    /// </summary>
    public static class SendHubs
    {
        /// <summary>
        /// 调用hub方法
        /// </summary>
        /// <param name="methodName"></param>
        /// <param name="args">参数</param>
        public static async Task callMethod(string methodName, params object[] args)
        {
            if (ConfigHelper.GetConfig().IMOpen) {
                var connection = new HubConnectionBuilder()
                    .WithUrl(ConfigHelper.GetConfig().IMUrl + "/ChatsHub")
                    .Build();
                await connection.StartAsync();
                await connection.InvokeAsync(methodName, args);
                await connection.StopAsync();
            }
            
        }
    }
}
